from grab import Grab
g = Grab()

INfile = 'C:/pysyn/syns.txt'
# every species on a new row
# (path to file for results)
OUTfile = open('C:/pysyn/CoLvalid.txt', 'w')
# write header with col names
OUTfile.write('sp_syn, sp_val\n')
# xPath
str_path="/html/body[@class='tundra']/div[@id='right-col']/div[@id='content']/table[@class='details-table']/tr[@class='even'][1]/td/table/tr/td[1]/i"

def main():
    # read into list rows
    rows = open(INfile).read().splitlines()

   
    for row in rows:
        sp_syn, sp_url = row.split(',')
        g.go(sp_url)
        sp_val = g.xpath(str_path).text_content()
        print(sp_syn + ' - > ' + sp_val)
        OUTfile.write(sp_syn + ',' + sp_val + '\n')
    OUTfile.close
    
# Standard boilerplate to call the main() function to begin
# the program.
if __name__ == '__main__':
    main()
